import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { i18n } from '@/locales';
import { ref } from 'vue';
import { commonCode } from '@/api/common/common_code';

export const colorList = ref();
(async () => {
  const res = await commonCode('color');
  colorList.value = res.result.map((item) => ({
    label: item.name,
    value: item.code,
  }));
})();

export type TableListItem = {
  id: number | string;
  serial: string;
  spec: string;
  color: string;
  distance: string;
  createTime: string;
  desp: string;
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    // @ts-ignore
    title: `冻存盒名称`,
    field: 'serial',
  },
  {
    title: '盒规格',
    field: 'spec',
    formatter: ({ row }) => {
      return `${row.rows}×${row.cols}`;
    },
    hideInSearch: true,
  },
  {
    title: '盒颜色',
    field: 'color',
    formatter: ({ cellValue }) => {
      return colorList.value?.find((item) => item.value === String(cellValue))?.label ?? '';
    },
    hideInSearch: true,
  },
  {
    // @ts-ignore
    title: `冻存盒冒距盒顶端高度（mm）`,
    field: 'distance',
    hideInSearch: true,
  },
  {
    title: '创建时间',
    field: 'createTime',
    hideInSearch: true,
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
  },
  {
    title: '描述',
    field: 'desp',
    hideInSearch: true,
  },
];
